﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Spritehand.FarseerHelper;
using System.Windows.Media.Imaging;
using System.Windows.Interactivity;
using Spritehand.PhysicsBehaviors;
using System.ComponentModel;

namespace DemoBehaviors1
{
    public partial class ucMainGame : UserControl
    {
        PhysicsControllerMain _physicsController;
        
        public ucMainGame()
        {
            InitializeComponent();

            if (DesignerProperties.GetIsInDesignMode(this) == true)
                return;

            // get a reference to the Physics Controller, which can be used to directly
            // access the Farseer Objects, Game Loop, etc.
            _physicsController = LayoutRoot.GetValue(PhysicsControllerMain.PhysicsControllerProperty) as PhysicsControllerMain;
            _physicsController.Initialized += new PhysicsControllerMain.InitializedHandler(_physicsController_Initialized);
            _physicsController.TimerLoop += new PhysicsControllerMain.TimerLoopHandler(_physicsController_TimerLoop);

            // METRICS - use these to ensure your elements are using the GPU
            //Application.Current.Host.Settings.MaxFrameRate = 30;
            Application.Current.Host.Settings.EnableFrameRateCounter = true;
            //Application.Current.Host.Settings.EnableCacheVisualization = true;
            //Application.Current.Host.Settings.EnableRedrawRegions = true;

        }

        void _physicsController_Initialized(object source)
        {
            // here you can do initialization stuff
            //sbAnimateWater.Begin();
        }

        void _physicsController_TimerLoop(object source)
        {
            // here you can handle logic per "frame"
        }

   
        private void btnAddBlock_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // create the block control and add to Canvas
            ucBlock newBlock = new ucBlock();
            Canvas.SetLeft(newBlock, 600);
            Canvas.SetTop(newBlock, -30);
            LayoutRoot.Children.Add(newBlock);
            // add the physics for the block
            _physicsController.AddPhysicsBodyForCanvasWithBehaviors(newBlock.LayoutRoot);
            // now we can remove the user control instance - block is part of game canvas.
            LayoutRoot.Children.Remove(newBlock);

        }

    }
}
